var ObjectStoreContext = Class.create({
    
    store: null,
    
    initialize: function(store)
    {
        this.store = store;
    },

    reset: function()
    {
        this.saveCache = new Hash();
        this.referenceCache = new Hash();
    },
    
    
    // call stack tracking
    depth: 0,
    pushDepth: function()
    {
        this.depth++;
    },
    popDepth: function()
    {
        this.depth--;
        if (this.depth == 0)
            this.reset();
    },
    
    atTopOfStack: function()
    {
        return this.depth <= 1;
    },
    
    
    
    // allocation shortcuts
    ensureStoreIsAllocatedFor: function(classToAllocate)
    {        
        if (!this.store.allocatedFor(classToAllocate))
        {
            var allocator = this.store.getAllocator();
            allocator.allocate([classToAllocate]);
        }
    },
    
    
    // reference cache
    referenceCache: new Hash(),
    getObject: function(classToRetrieve, objectIdentifier)
    {
        // TODO: implement the reference cache so we don't multiply-hydrate
        //       objects in a single call
        return null;
    },
	
	getObjects: function(classToRetrieve)
    {
        // TODO: implement the reference cache so we don't multiply-hydrate
        //       objects in a single call
        return null;
    },
	
    findObject: function(searchClass, searchObject)
    {
        // TODO: implement the reference cache so we don't multiply-hydrate
        //       objects in a single call
        return null;
    },
	
	findObjects: function(searchClass, searchObject)
    {
        // TODO: implement the reference cache so we don't multiply-hydrate
        //       objects in a single call
        return null;
    },
    
    // saved object tracking
    saveCache: new Hash(),
    registerSavedObject: function(object)
    {
        // TODO: implement this: with these methods, we'll have infinite recursion when
        //       the graph has cycles
    },
    hasObjectBeenSaved: function(object)
    {
        return false;
        // TODO: implement this: with these methods, we'll have infinite recursion when
        //       the graph has cycles
    },
    
    
    // transaction tracking
    transactionDepth: 0,
    pushTransactionDepth: function()
    {
        this.transactionDepth++;
    },
    popTransactionDepth: function()
    {
        this.transactionDepth--;
        if (this.transactionDepth == 0)
            this.reset();
    },
    beginImplicitTransaction: function()
    {
        console.log("Beginning implicit transaction...")
        this.pushTransactionDepth();
        if (this.currentTransaction == null)
            this.currentTransaction = this.store.createTransaction();
    },
    commitImplicitTransaction: function()
    {
        console.log("Committing implicit transaction...")
        this.popTransactionDepth();
        if (this.transactionDepth == 0)
            this.currentTransaction.commit();
    }
});
